package com.zb.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.constant.WorkConstant;
import com.zb.entity.ZjWorkReassign;
import com.zb.mapper.ZjWorkReassignMapper;
import com.zb.service.ZjWorkReassignService;
import com.zb.vo.WorkWaitCheckReassignVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 工单改派表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-10-23
 */
@Service
public class ZjWorkReassignServiceImpl extends ServiceImpl<ZjWorkReassignMapper, ZjWorkReassign> implements ZjWorkReassignService {

    // 根据服[服务商ID]&[工单ID]获取改派信息
    @Override
    public ZjWorkReassign getByNetworkIdAndWorkId(Long networkId, Long workId) {
        QueryWrapper<ZjWorkReassign> wrapper = new QueryWrapper<>();
        wrapper.eq("network_id", networkId).eq("work_id", workId);
        return this.getOne(wrapper);
    }

    // 根据工单ID获取待审核改派服务商的工单
    @Override
    public ZjWorkReassign getWaitCheckWorkReassign(Long workId) {
        QueryWrapper<ZjWorkReassign> wrapper = new QueryWrapper<>();
        wrapper.select("id", "current_network_id", "status", "apply_emp_type", "apply_emp", "apply_remark", "gmt_create", "gmt_update")
        .eq("work_id", workId).eq("status", WorkConstant.WORK_REASSIGN_STATUS_1);
        return this.getOne(wrapper);
    }

    // 根据服务商ID与工单ID获取服务商申请改派服务商待审核的工单
    @Override
    public List<ZjWorkReassign> getWaitCheckWorkReassignByNetworkIdAndWorkIds(Long networkId, List<Long> workIds) {
        if (CollectionUtil.isEmpty(workIds)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjWorkReassign> wrapper = new QueryWrapper<>();
        wrapper.select("id", "work_id", "current_network_id", "status", "apply_emp_type", "apply_emp", "apply_remark", "gmt_create", "gmt_update")
                .eq("current_network_id", networkId)
                .eq("status", WorkConstant.WORK_REASSIGN_STATUS_1)
                .in("work_id", workIds);
        return this.list(wrapper);
    }
}
